﻿describe("Strategies/HiddenSingle", function () {

    var hiddenSingle;

    beforeEach(function () {
        hiddenSingle = new Strategies.HiddenSingle();
    });

    describe("should find by:", function () {

        it("row", function () {
            var expectedShortString = "--9--8--6-68-3--9-7--6924--4--76-5---7-85--24-95214--8--63-1--2-3--2-86-8--9--3--";
            var gridModel = GridModel.fromShortString("--9--8--6-6--3--9-7--6924--4--76-5---7-85--24-95214--8--63-1--2-3--2-86-8--9--3--");
            SolvingHelper.fillCandidates(gridModel);

            //do
            var performResult = hiddenSingle.perform(gridModel);
            expect(performResult).toBeTruthy();
            expect(performResult.cell).toEqual(gridModel.cells[1][2]);
            expect(performResult.deduction).toEqual("row");

            expect(expectedShortString).toEqual(gridModel.toShortString());
        });

        it("column", function () {
            var expectedShortString = "-----------39-78---5-42--6--3-1-2-8-1-9-8-7---6-3-4-1--1-75--2---68-94-----2-----";
            var gridModel = GridModel.fromShortString("-----------39-78---5-42--6--3-1-2-8-1-9-8-7---6-3-4-1--1--5--2---68-94-----2-----");
            SolvingHelper.fillCandidates(gridModel);

            //do
            var performResult = hiddenSingle.perform(gridModel);
            expect(performResult).toBeTruthy();
            expect(performResult.cell).toEqual(gridModel.cells[6][3]);
            expect(performResult.deduction).toEqual("column");

            expect(expectedShortString).toEqual(gridModel.toShortString());
        });

        it("region", function () {
            var expectedShortString = "----------534--26--9-2---8----65-8373-58-7---86734-----1---3-4--34--652------4---";
            var gridModel = GridModel.fromShortString("----------534--26--9-2---8----65-8373--8-7---86734-----1---3-4--34--652------4---");
            SolvingHelper.fillCandidates(gridModel);

            //do
            var performResult = hiddenSingle.perform(gridModel);
            expect(performResult).toBeTruthy();
            expect(performResult.cell).toEqual(gridModel.cells[4][2]);
            expect(performResult.deduction).toEqual("region");

            expect(expectedShortString).toEqual(gridModel.toShortString());
        });
    });
});

